package com.mall.service;


import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.api.OmsOrderReturnApplyApi;
import com.mall.dto.OmsOrderReturnApplyDto;
import com.mall.pageResult.PageResult;
import com.mall.pojo.OmsOrder;
import com.mall.pojo.OmsOrderReturnApply;
import com.mall.pojo.OmsOrderReturnReason;
import com.mall.pojo.OmsUpdateStatusParam;
import com.mall.vo.OmsOrderReturnApplyVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OmsOrderReturnApplyService {

    @DubboReference
    private OmsOrderReturnApplyApi omsOrderReturnApplyApi;

    /**
     * 退货申请处理的分页查询
     * @param ooD
     * @return
     */
    public PageResult<OmsOrderReturnApply> pageOrderReturnApply(OmsOrderReturnApplyDto ooD) {
        //调用Api进行分页查询
        Page<OmsOrderReturnApply> page = omsOrderReturnApplyApi.pageOrderReturnApply(ooD);
        PageResult<OmsOrderReturnApply> pageRe = new PageResult<>();
        pageRe.setPageNum(ooD.getPageNum());
        pageRe.setPageSize(ooD.getPageSize());
        pageRe.setList(page.getRecords());
        pageRe.setTotalPage(Convert.toInt(page.getPages()));
        pageRe.setTotal(Convert.toInt(page.getTotal()));
        return pageRe;

    }

    /**
     * 根据id进行查询申请退货处理数据详情
     * @param id
     * @return
     */
    public OmsOrderReturnApplyVo findOrderReturnApplyById(Integer id) {

        //调用方法进行查询
        OmsOrderReturnApplyVo ooRa =    omsOrderReturnApplyApi.findOrderReturnApplyById(id);

        return ooRa;
    }

    /**
     * 修改用户状态
     * @param id
     * @param statusParam
     * @return
     */
    public Integer updateOrderReturnApplyStatus(Integer id, OmsUpdateStatusParam statusParam) {
        //封装数据
        statusParam.setId(id.longValue());
        //调用方法进行修改
       Integer updateRe =  omsOrderReturnApplyApi.updateOrderReturnApplyStatus(statusParam);

       return updateRe;


    }


    /**
     * 批量删除退货申请
     * @param ids
     * @return
     */
    public Integer deleteOrderReturnApply(List<Integer> ids) {
        //调用方法进行删除
       Integer deleteNum =  omsOrderReturnApplyApi.deleteOrderReturnApply(ids);

       //返回参数
        return deleteNum;


    }
}
